package com.mc.web;

import org.apache.log4j.Logger;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mc.model.Path;
import com.mc.model.Xy;
import com.mc.model.Xyjb;
import com.mc.service.IXyjbService;
import com.mc.service.IXyxyService;
import com.mc.utils.PathUtil;
import com.mc.utils.TraderCenterUtil;
@Controller
public class YxxyAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(YxxyAction.class);
	
	@Autowired IXyxyService xyxyService;
	@Autowired IXyjbService xyjbService;
   private Path path = null;
   /**
    * 
    * @param modelMap
    * @return 优秀校友界面
    */
   @RequestMapping("/yxxy")
   public String mooc(ModelMap modelMap)
   {List<Xyjb> jbs = xyjbService.selectallxyjb();
   modelMap.addAttribute("jbs", jbs);
	   path = PathUtil.setPathParams(new String[]{"PackageName:yxxy","ViewName:yxxy","ViewTitle:优秀校友简介","smenu:zsjy","mmenu:yxxy"});
		return PathUtil.returnStr(path, modelMap);
   }
   /**
    * 
    * @param modelMap
    * @return 优秀毕业生简介
    */
   @RequestMapping("/yxbys")
   public String yxbys(ModelMap modelMap)
   {
	   List<Xyjb> jbs = xyjbService.selectallxyjb();
	   modelMap.addAttribute("jbs", jbs);
	   
	   path = PathUtil.setPathParams(new String[]{"PackageName:yxxy","ViewName:yxbys","ViewTitle:优秀毕业生简介","smenu:zsjy","mmenu:yxbys"});

	   return PathUtil.returnStr(path, modelMap);
   }
   /**
    * 
    * @param id
    * @param request
    * @param modelMap
    * @return
    */
   @RequestMapping("/yxbyss/{id}")
   public String yxbyss(@PathVariable("id") int id,HttpServletRequest request,ModelMap modelMap){
	   //logger.info("test--");
	   
	   
	   List<Xyjb> jbs = xyjbService.selectallxyjb();
	   modelMap.addAttribute("jbs", jbs);
	   List<String> jss =  xyxyService.selectalljs(id);
	   
	   List<Xy> xies = xyxyService.selectxymaxjs(id);
	   
	   modelMap.addAttribute("xies",xies);
	   
	   modelMap.addAttribute("jss", jss);
	   modelMap.addAttribute("jbid",id);
	   path = PathUtil.setPathParams(new String[]{"PackageName:yxxy","ViewName:yxbys","ViewTitle:优秀毕业生简介","smenu:zsjy","mmenu:yxbys","mmmenu:"+id});
	   return PathUtil.returnStr(path, modelMap);
   }
   /**
    * 
    * @param modelMap
    * @return
    */
   @RequestMapping("/learning")
   public String learing(ModelMap modelMap)
   {
	   path = PathUtil.setPathParams(new String[]{"PackageName:Learning","ViewName:learing","ViewTitle:学习园地","smenu:learning","mmenu:yxbys"});
		return PathUtil.returnStr(path, modelMap);
   }
   /**
    * 
    * @param id 
    * @param request
    * @param modelMap
    * @param js
    * @return
    */
   
   @RequestMapping("/getXt/{id}")
   @ResponseBody
   public String getXt(@PathVariable("id") int id,HttpServletRequest request,ModelMap modelMap,
		   @RequestParam(value="js",required=false)String js){
	   String result = "";
	   if(js!=null){
		  // logger.info(js);
		   List<Xy> xies = xyxyService.selectbyjsandjb(id, js);
		   //logger.info(xies.toString());
		   if(xies!=null){
			   xies.get(0).setCount(xies.size());
		   }
		   result = TraderCenterUtil.getInstance().ParseListToJSON(xies);
	   }
	   return result;
   }
   /**
    * 
    * @param modelMap
    * @param id
    * @return
    */
   @RequestMapping("/xybys/detail/{id}")
   public String detail(ModelMap modelMap,@PathVariable("id")int id){
	   List<Xyjb> jbs = xyjbService.selectallxyjb();
	   modelMap.addAttribute("jbs", jbs);
	   Xy xy =  xyxyService.selectByPrimaryKey(id);
	   modelMap.addAttribute("xy", xy);
	   //logger.info(xy.toString());
	   path = PathUtil.setPathParams(new String[]{"PackageName:yxxy","ViewName:detail","ViewTitle:优秀毕业生简介","smenu:zsjy","mmenu:yxbys","mmmenu:"+xy.getXyJb().getXyjbId()});
		return PathUtil.returnStr(path, modelMap);
   }
}
